" File: class_inspector.vim
" Author: Dardo Marasca 
" Version: 0.1
" Last Modified: November 12, 2012
"

let s:cpo_save = &cpo
set cpo&vim

if !exists("ClassInspector_Path")
    let ClassInspector_Path = '/home/dmarasca/bin/inspector.pl' 
endif

function! s:RunInspectClassCmd(class)
    let cmd_output = system(g:ClassInspector_Path . ' ' . a:class)

    if cmd_output == ""
        echohl WarningMsg | 
        \ echomsg "Error: class " . a:class . " not found" | 
        \ echohl None
        return
    endif

    let tmpfile = tempname()

    let old_verbose = &verbose
    set verbose&vim

    exe "redir! > " . tmpfile
    silent echon '[Class ' . a:class . " methods]\n"
    silent echon cmd_output
    redir END

    let &verbose = old_verbose

    let old_efm = &efm
    set efm=%f:%\\s%#%l:%m

	if exists(":cgetfile")
		execute "silent! cgetfile " . tmpfile
	else
		execute "silent! cfile " . tmpfile
	endif

    let &efm = old_efm

    botright copen 25

    call delete(tmpfile)
endfunction

function! s:RunInspectClass()

    let class = input("Methods for class: ", expand("<cword>"))
    if class == ""
        return
    endif

    call s:RunInspectClassCmd(class)
endfunction

command! -nargs=* -complete=file InspectClass
            \ call s:RunInspectClass()

let &cpo = s:cpo_save
unlet s:cpo_save

